<?php
/*
 * Created on Apr 15, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

require_once("model/MenuItemEnum.php");
require_once("bizlayer/player_mgmt.php");
require_once("bizlayer/course_mgmt.php");
require_once("bizlayer/venue_mgmt.php");
require_once("bizlayer/hole_mgmt.php");
require_once("bizlayer/result_mgmt.php");
require_once("bizlayer/photo_mgmt.php");
require_once("bizlayer/session_mgmt.php");
require_once("bizlayer/import_status_mgmt.php");
require_once("bizlayer/datamigration_mgmt.php");
require_once("bizlayer/result_mgmt.php");
require_once("bizlayer/event_mgmt.php");
require_once("model/WizardSteps.php");
include_once("model/Player.php");
include_once("model/Photo.php");

class Model{
	
	private static $instance = null;
	public $selected = null;
	public $isAdmin = false;
	public $adminMode = false;
	public $listItems = null;
	public $listAdminItem = null;
	
	private function __construct(){
		$this->selected = MenuItemEnum::HOME;
		$this->isAdmin = false;
		$this->adminMode = false;
		$this->listItems = array(MenuItemEnum::HOME=>"Home",MenuItemEnum::YEARS=>"Years",MenuItemEnum::COURSES=>"Courses",MenuItemEnum::PLAYERS=>"Players",MenuItemEnum::RULES=>"Rules");
		$this->listAdminItem = array(AdminItemEnum::PLAYER_MGMT=>"Player Management",
								AdminItemEnum::RESULT_IMPORT=>"Results Import",
								AdminItemEnum::COURSES=>"Courses/Holes",
								AdminItemEnum::EVENT_YEARS=>"Event Years",
								AdminItemEnum::RULES=>"Rules");
	}
	
	private function __clone(){}
	
	public static function getInstance(){
 		if(!isset(self::$instance)){
 			$className = __CLASS__;
 			self::$instance = new $className;
 		}
 		return self::$instance;
 	}
	
	public function getPlayerById($playerId){
		$playerDao = DAOFactory::getDAO("player");
		return $playerDao->getItem($playerId);
	}
	
	public function getStandingByYear($playerId){
		return PlayerMgmt::getStandingByYear($playerId);
	}
	
	
	public function getProfilePic($playerId){
		return PlayerMgmt::getProfilePic($playerId);
	}
	
	public function addPlayerPhoto($caption,$imageData,$imageDataM,$imageDataT,$imgType,$size,$name,$ext,$playerid,$isProfPic){
		return PlayerMgmt::addPhoto($caption,$imageData,$imageDataM,$imageDataT,$imgType,$size,$name,$ext,$playerid,$isProfPic);
	}
	
	public function getPhoto($photoId){
		return PhotoMgmt::getItem($photoId);
	}
	
	public function getPhotosByPlayerId($playerId){
		return PlayerMgmt::getPhotosByPlayerId($playerId);
	}
	
	public function setProfilePic($playerid,$photoid){
		PlayerMgmt::setProfilePic($playerid, $photoid);
	}
	
	public function deletePhotos($photoIdList){
		PhotoMgmt::deletePhotos($photoIdList);
	}
		
 	public function login($emailAddr,$pw){
 		return SessionMgmt::login($emailAddr,$pw);
	}
	
	public function searchPlayer($firstname,$mi,$lastname,$emailaddress,$hometown,$currentcity,$verified,$locked,$admin){
		return PlayerMgmt::searchPlayer($firstname,$mi,$lastname,$emailaddress,$hometown,$currentcity,$verified,$locked,$admin);
	} 

	public function getAppearance($playerId){
		return PlayerMgmt::getAppearance($playerId);
	}
	public function getResultByYear($eventid){
		return ResultMgmt::getResultByYear($eventid);
 	}
 	
 	public function getChampions(){
 		return ResultMgmt::getChampions();
 	}
 	
 	public function getSureshotWinners(){
 		return ResultMgmt::getSureshotWinners();
 	}
 	
 	public function updatePlayer($player){
 		PlayerMgmt::updatePlayer($player);	
 	}
 	
 	public function getLatestEvent(){
 		$eventDao = DAOFactory::getDAO("event");
 		return $eventDao->getLatestEvent();
	}
	
	public function getEventById($eventid){
		return EventMgmt::getEventById($eventid);
	}
	
	/*********************************************
	 * Course management related methods
	********************************************/
	
	public function searchCourses($venueId,$courseName){
		return CourseMgmt::searchCourses($venueId, $courseName, 0);
	}
	public function getCourseListByVenueId($venueId){
		return CourseMgmt::getCourseListByVenueId($venueId);
	}
	public function getAllCourses(){
		return CourseMgmt::getAllCourses();
	}
	public function getCourse($courseid){
		return CourseMgmt::getCourse($courseid);
	}
	
	public function getVenue($venueid){
		return VenueMgmt::getVenueById($venueid);
	}
	
	public function getVenuePhoto($venueid){
		return VenueMgmt::getVenuePhoto($venueid);
	}
	
	public function updateVenue($venue){
		VenueMgmt::updateVenue($venue);
	}
	
	public function updateVenuePhoto($venueid,$venueImgData){
		VenueMgmt::updatePhoto($venueid, $venueImgData);
	}
	
	public function saveCourse($course){
		CourseMgmt::updateCourse($course);
	}
	
	public function deleteCourse($courseid){
		CourseMgmt::deleteCourse($courseid);
	}
	
	public function getAllVenues(){
		return VenueMgmt::getAllVenues();
	}
	
	public function getHolesByCourseId($courseid){
		return HoleMgmt::searchHoles(null, $courseid, null, null);
	}
	
	/*********************************************
	 * Data Migration related methods
	 ********************************************/
	
	public function createImportStatus($imptStatus){
		return ImportStatusMgmt::createImportStatus($imptStatus);
	}
	
	public function getImportStatus($adminId,$imptStatusId){
		return ImportStatusMgmt::getImportStatus($adminId,$imptStatusId);
	}
	
	public function deleteImportStatus($val){
		ImportStatusMgmt::deleteImportStatus($val);
	}
	
	public function fillInIds(){
		DataMigrationMgmt::fillInIds();
	}
	
	public function listNewPlayers($importStatusId){
		return DataMigrationMgmt::listNewPlayers($importStatusId);
	}
	
	public function listNewCourses($importStatusId){
		return DataMigrationMgmt::listNewCourses($importStatusId);
	}
	
	public function insertNewPlayers(){
		DataMigrationMgmt::insertNewPlayers();
	}
	
	public function displayContents($importStatusId){
		return DataMigrationMgmt::displayContents($importStatusId);
	}
	
	public function importResults($importStatusId){
		DataMigrationMgmt::importResults($importStatusId);
	}
	
	public function bulkInsert($filePath,$eventYear,$importStatusID){
		return DataMigrationMgmt::bulkInsert($filePath,$eventYear,$importStatusID);
	}
}
?>
